package com.shj.em.biz.sys.service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.shj.em.biz.sys.entity.CdType;
import com.shj.em.biz.sys.mapper.CdTypeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 代码项 服务实现类
 *
 * @author Shen Huang Jian
 * @since 2018-07-04
 */
@Service
public class CdTypeServiceImpl extends ServiceImpl<CdTypeMapper, CdType> implements CdTypeService {

    @Autowired
    CdTypeMapper cdtypeMapper;

    public Page<CdType> queryCdTypePage(Map<String, Object> params){
        int offset = (Integer)params.get("offset");
        int pageSize = (Integer)params.get("limit");
        int pageNo = offset / pageSize + 1;
        Page<CdType> page = new Page<>(pageNo, pageSize);
        List<CdType> list = cdtypeMapper.queryCdTypePage(page, params);
        return page.setRecords(list);
    }

    public boolean isCdTypeExist(String type, Long excludeId){
        Wrapper<CdType> wrapper = new EntityWrapper<>();
        wrapper.eq("type", type).eq("del_flag", 0);
        if(excludeId != null){
            wrapper.ne("id", excludeId);
        }
        List<CdType> list = cdtypeMapper.selectList(wrapper);
        return list != null && list.size() > 0;
    }
}
